home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / snip9_91.arc / SETVOL.C < prev    next >
C/C++ Source or Header  |  1991-09-17  |  3KB  |  116 lines

  1. /*
  2. **  SETVOL.C - set, change, or kill a disk volume label
  3. **
  4. **  public domain demo by Bob Stout
  5. */
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <dos.h>
  10. #include <io.h>
  11.  
  12. #if defined(__TURBOC__)
  13.  #pragma option -a-
  14.  #include <dir.h>
  15.  #define _dos_findfirst(f,a,b) findfirst(f,b,a)
  16.  #define _dos_findnext(b) findnext(b)
  17.  #define find_t ffblk
  18.  #define _A_VOLID FA_LABEL
  19.  #define attrib ff_attrib
  20.  #define name ff_name
  21.  #define size ff_size
  22.  #define wr_time ff_time
  23.  #define wr_date ff_date
  24.  #define dos_creat _creat
  25. #else
  26.  #include <direct.h>
  27.  #if defined(__ZTC__)
  28.   #pragma ZTC align 1
  29.   #if __ZTC__ < 0x210
  30.    #include <mflfiles.h>  /* old ZTC didn't do recursive find first/next  */
  31.    #include <msport.h>    /* ...so use MFLZT library functions            */
  32.   #endif
  33.  #else /* MSC/QC/WATCOM/METAWARE */
  34.   #pragma pack(1)
  35.   int dos_creat(const char *fname, unsigned attrib)
  36.   {
  37.         int fd;
  38.  
  39.         if (_dos_creat(fname, attrib, &fd))
  40.                 return -1;
  41.         else    return fd;
  42.   }
  43.  #endif
  44.  struct fcb {
  45.          char   fcb_drive;
  46.          char   fcb_name[8];
  47.          char   fcb_ext[3];
  48.          short  fcb_curblk;
  49.          short  fcb_recsize;
  50.          long   fcb_filsize;
  51.          short  fcb_date;
  52.          char   fcb_resv[10];
  53.          char   fcb_currec;
  54.          long   fcb_random;
  55.  };
  56.  
  57.  struct xfcb {
  58.          char           xfcb_flag;
  59.          char           xfcb_resv[5];
  60.          char           xfcb_attr;
  61.          struct fcb     xfcb_fcb;
  62.  };
  63. #endif
  64.  
  65. void vol_kill(char *fname)
  66. {
  67.         union REGS regs;
  68.         struct SREGS sregs;
  69.         struct xfcb buf;
  70.  
  71.         /* Parse the filename into an FCB               */
  72.         segread(&sregs);
  73.         regs.h.ah = 0x29;
  74.         regs.h.al = 0;
  75.         regs.x.si = (unsigned)fname;
  76.         regs.x.di = (unsigned)&buf.xfcb_fcb;
  77.         sregs.es  = sregs.ds;
  78.         intdosx(®s, ®s, &sregs);
  79.  
  80.         /* Volume labels require extended FCB's         */
  81.         buf.xfcb_flag = 0xff;
  82.         buf.xfcb_attr = _A_VOLID;
  83.  
  84.         /* Delete the old label                         */
  85.         regs.h.ah = 0x13;
  86.         regs.x.dx = (unsigned)&buf;
  87.         intdos(®s, ®s);
  88. }
  89.  
  90. void setvol(char *label)
  91. {
  92.         int fd;
  93.         struct find_t finfo;
  94.         union REGS regs;
  95.  
  96.         chdir("\\");            /* Move to the root directory   */
  97.         /* If drive is already labeled, remove it               */
  98.         if (0 == _dos_findfirst("*.*", _A_VOLID, &finfo)) do
  99.         {       if (_A_VOLID & finfo.attrib)
  100.                         break;
  101.         } while (0 == _dos_findnext(&finfo));
  102.         if (_A_VOLID & finfo.attrib)
  103.                 vol_kill(finfo.name);
  104.         fd = dos_creat(label, _A_VOLID); /* Create new label    */
  105.         close(fd);
  106. }
  107.  
  108. void main(int argc, char *argv[])
  109. {
  110.         if (2 > argc)
  111.         {       puts("\aUsage: SETVOL new_name");
  112.                 abort();
  113.         }
  114.         setvol(argv[1]);
  115. }
  116.